//
//  calcBrain.m
//  calculator
//
//  Created by Will Martin on 5/4/10.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import "calcBrain.h"


@implementation calcBrain

-(void)performWaitingOperation{
	if([@"+" isEqual:waitingOperation]){
		operand = waitingOperand + operand;
	}
	else if ([@"*" isEqual:waitingOperation]){
		operand = waitingOperand * operand;
	}
	else if ([@"-" isEqual:waitingOperation]){
		operand = waitingOperand - operand;
	}
	else if ([@"/" isEqual:waitingOperation]){
		if(operand)
			operand = waitingOperand / operand;
	}
	
}

-(void)setOperand:(double)aDouble{
	
	operand = aDouble;
	
}

-(double)performOperation:(NSString *)operation{
	
	if([operation isEqual:@"sqrt"]) {
		operand = sqrt(operand);
	}
	else if ([@"+/-" isEqual:operation]){
		operand=-operand;
	}
	else{
		[self performWaitingOperation];
		waitingOperation = operation;
		waitingOperand = operand;
	}
	return operand;
}

@end
